package net.jltec.view.bean;

import java.io.Serializable;

public class Page implements Serializable{

	/**
	 * 当前第几页
	 */
	private int pageIndex;

	/**
	 * 总页数
	 */
	private int totalPageCount;

	public int getPageIndex() {
		return pageIndex;
	}


	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}


	public int getTotalPageCount() {
		return totalPageCount;
	}


	public void setTotalPageCount(int totalPageCount) {
		this.totalPageCount = totalPageCount;
	}


	public int getTotalCount() {
		return totalCount;
	}


	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public boolean isHasNextPage() {
		return hasNextPage;
	}


	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}


	public boolean isHasPreviousPage() {
		return hasPreviousPage;
	}


	public void setHasPreviousPage(boolean hasPreviousPage) {
		this.hasPreviousPage = hasPreviousPage;
	}


	/**
	 * 总记录数
	 */
	private int totalCount;

	/**
	 * 当前页第一条数据的位置,从0开始
	 */

	/**
	 * 每页的记录数
	 */
	private int pageSize;

	/**
	 * 是否有下一页
	 */
	private boolean hasNextPage = true;

	/**
	 * 是否有上一页
	 */
	private boolean hasPreviousPage = true;
	
	public Page(int pageSize, int pageIndex,int totalCount){
		this.pageSize = pageSize;
		this.pageIndex = pageIndex;
		this.totalCount = totalCount;
		
		init();
	}
	
	
	private void init() {
		totalPageCount = totalCount / pageSize;
		int mod = totalCount % pageSize;
		if (mod > 0) {
			totalPageCount++;
		}
		if (totalPageCount <= pageIndex) {
			pageIndex = totalPageCount;
			hasNextPage = false;
		}

		if (pageIndex <= 1) {
			hasPreviousPage = false;
		}
		
	}
}
